//
//  XQHomeFiveTableViewCell.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/11/28.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQHomeFiveTableViewCell: UITableViewCell {

    var icon = UIImageView()
    var titlelabel = UILabel()
    
    var typeLabel1 = UILabel()
    var typeLabel2 = UILabel()
    var typeLabel3 = UILabel()

    var salaryLabel = UILabel()
    var peopleLabel = UILabel()
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        InitUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var courseMode:XQHomeCourseMode?{
        didSet{
            let url = URL(string: (courseMode?.course_photo)!)
            icon.kf.setImage(with: url)
       
            
            titlelabel.text = courseMode?.course_name
            if courseMode?.type == "video" {
                typeLabel1.text = "视频课"
            }else if courseMode?.type == "train" {
                typeLabel1.text = "培训课"
            }else{
                typeLabel1.text = "直播课"
            }
            
            typeLabel2.text = courseMode?.author
            typeLabel3.text = courseMode?.status
            
            let price = Float((courseMode?.price)!)
            if price == 0 {
                salaryLabel.text = "免费"
            }else{
                salaryLabel.text = "¥" + (courseMode?.price)!
            }
            if ((courseMode?.study_num) != nil) {
                let str1 = "学习人数:" + (courseMode?.study_num)!
                let attributeString = NSMutableAttributedString(string:str1)
                attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.orange,
                                             range: NSMakeRange(5, (courseMode?.study_num?.lengthOfBytes(using: String.Encoding.utf8))!))
                peopleLabel.attributedText = attributeString
            }
      
        }
    }
    
    func InitUI() {
    
        icon = UIImageView.init(frame: CGRect.zero)
        self.contentView.addSubview(icon)
        
        titlelabel = UILabel.init(frame: CGRect.zero)
        self.contentView.addSubview(titlelabel)
        
        typeLabel1 = UILabel.init(frame: CGRect.zero)
        typeLabel1.font = UIFont.systemFont(ofSize: 12)
        typeLabel1.layer.borderWidth = 0.5
        typeLabel1.layer.borderColor = UIColor.lightGray.cgColor
        self.contentView.addSubview(typeLabel1)

        typeLabel2 = UILabel.init(frame: CGRect.zero)
        typeLabel2.font = UIFont.systemFont(ofSize: 12)
        typeLabel2.layer.borderWidth = 0.5
        typeLabel2.layer.borderColor = UIColor.lightGray.cgColor
        self.contentView.addSubview(typeLabel2)

        typeLabel3 = UILabel.init(frame: CGRect.zero)
        typeLabel3.font = UIFont.systemFont(ofSize: 12)
        typeLabel3.layer.borderWidth = 0.5
        typeLabel3.layer.borderColor = UIColor.lightGray.cgColor
        self.contentView.addSubview(typeLabel3)

        salaryLabel = UILabel.init(frame: CGRect.zero)
        salaryLabel.font = UIFont.systemFont(ofSize: 13)
        self.contentView.addSubview(salaryLabel)

        peopleLabel = UILabel.init(frame: CGRect.zero)
        peopleLabel.font = UIFont.systemFont(ofSize: 13)
        self.contentView.addSubview(peopleLabel)

        icon.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView.snp.left).offset(5)
            make.top.equalTo(self.contentView.snp.top).offset(10)
            make.width.equalTo(100)
            make.height.equalTo(60)
        }
        
        titlelabel.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(3)
            make.top.equalTo(self.contentView.snp.top).offset(5)
            
        }
        
        typeLabel1.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(3)
            make.centerY.equalTo(self.contentView.snp.centerY)
        }
        
        typeLabel2.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel1.snp.right).offset(5)
            make.centerY.equalTo(self.contentView.snp.centerY)
        }
        
        typeLabel3.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel2.snp.right).offset(5)
            make.centerY.equalTo(self.contentView.snp.centerY)
        }
        
        salaryLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.contentView.snp.bottom).offset(-5)
            make.left.equalTo(icon.snp.right).offset(5)
        }
        
        peopleLabel.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.contentView.snp.bottom).offset(-5)
            make.right.equalTo(self.contentView.snp.right).offset(-5)
        }
    
    }
    
    

    
    
}
